package com.cxyw.qqrobot.service;


import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;

@Service
@Log4j2
public class RedisService {

    @Autowired
    private  RedisTemplate<String, String> redisTemplate;


    public void set(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public void set(String key, String value,long seconds) {
        redisTemplate.opsForValue().set(key, value, Duration.ofSeconds(seconds));
    }

    public String get(String key) {
        return redisTemplate.opsForValue().get(key);
    }


    //获取expire
    public Long getExpire(String key){
        return redisTemplate.getExpire(key);
    }

    /**删除key*/
    public void delete(String key){
        redisTemplate.delete(key);
    }
}
